﻿Ext.namespace('EHSubmit.BBS');
var AnnID = '';
var Topic = '';
var Body = '';
var UserName = '';
var SubmitTime = '';
var DepartmentName = '';
EHSubmit.BBS.AnnData = {
    AID:'',
    DepartmentName:'',
    Topic:'',
    Body:'',
    UserID:'',
    UserName:'',
    DepartmentID:'',
    rescnt:'',
    resLastTime:'',
    SubmitTime:''
};

Ext.namespace('EHSubmit.BBS.Ann');




EHSubmit.BBS.Ann.addAnn = function addAnn() {

    EHSubmit.showWin(EHSubmit.BBS.AddAnn.window);
};



//---------------设置列字段-------------------------------
EHSubmit.BBS.Ann.colModel = new Ext.grid.ColumnModel([
        { header: '问题ID', id: 'AnnID', dataIndex: 'AID', hidden: true, hideable: false },
        { header: '专业', id: 'DepartmentName', dataIndex: 'DepartmentName', width: 120 },
        { header: '标题', id: 'Topic', dataIndex: 'Topic', width: 800 },
        //{ header: '帖子内容', id: 'Body', dataIndex: 'Body', hidden: true, hideable: false },
        { header: '提问人ID', id: 'SubmitID', dataIndex: 'UserID', hidden: true, hideable: false },
        { header: '提问人姓名', id: 'SubmitName', dataIndex: 'UserName', width: 100 },
        { header: '专业ID', id: 'DepartmentID', dataIndex: 'DepartmentID', hidden: true, hideable: false },
        { header: '回复数', id: 'rescnt', dataIndex: 'rescnt', width: 80 },
        { header: '最近回复', id: 'resLastTime', dataIndex: 'resLastTime', width: 110, renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s') },
        { header: '提问时间', id: 'SubmitTime', dataIndex: 'SubmitTime', width: 110, renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s') }
    ]);




EHSubmit.BBS.Ann.store = new Ext.data.Store({
        id: 'AnnGridStore',
        baseParams: { Op: 'AnnPage' },      //需要传递操作参数
        proxy: new Ext.data.HttpProxy({ url: EHSubmit.ajaxRoot + 'BBSHandler.ashx' }),  

        reader: new Ext.data.JsonReader({
            isSuccess: 'success',               
            totalProperty: 'totalProperty',    
            root: 'Ann'
        }, [
        { name: 'AID' },
        //{ name: 'Department' },
        { name: 'Topic' },
        { name: 'UserID' },
        { name: 'UserName' },
        { name: 'Body' },
        { name: 'rescnt' },
        { name: 'DepartmentID' },
        { name: 'DepartmentName' },
        { name: 'resLastTime' },
        { name: 'SubmitTime' }
        ]),
        listeners: {
        /// 加载异常处理
        exception: function(proxy, type, action, options, response){
            Ext.MessageBox.alert('数据加载错误!','请与管理员联系');
            
        }
    }
   });




   EHSubmit.BBS.Ann.grid = {
       xtype: 'grid',
       id: 'AnnGrid',

       store: EHSubmit.BBS.Ann.store,
       cm: EHSubmit.BBS.Ann.colModel,
       sm: new Ext.grid.RowSelectionModel({
           singleSelect: true             // 一次只选一个
       }),
       layout: 'fit',
       loadMask: true,
       height: 410,
       frame: true,
       //columnLines: true,
       buttonAlign: 'left',
       viewConfig: {
           forceFit: true,
           enableRowBody: true,
           showPreview: true,
           getRowClass: function(record, rowIndex, p, ds) {
               var str = record.data.Body;
               if (this.showPreview) {
                   if (str.length > 30) {
                       p.body = '<p><br>&nbsp;&nbsp;&nbsp;&nbsp;内容：' + Ext.util.Format.substr(record.data.Body, 0, 30) + '...</p><br>';
                       return 'x-grid3-row-expanded'; 
                   }
                   else {
                       p.body = '<p><br>&nbsp;&nbsp;&nbsp;&nbsp;内容：' + record.data.Body + '</p><br>';
                       return 'x-grid3-row-expanded';
                   }
                   
               }
               return 'x-grid3-row-collapsed';
           }
       },
       tbar: [
        {
            text: '提出问题',
            tooltip: '提出问题',
            iconCls: 'icon-write',
            handler: EHSubmit.BBS.Ann.addAnn
        },
        '  ',
        {
            pressed: true,
            enableToggle: true,
            text: '详细显示',
            tooltip: '显示详细内容',
            iconCls: 'add',
            toggleHandler: toggleDetails
        }
        ],

       bbar: {
           id: 'AnnGridPage',
           xtype: 'paging',
           pageSize: 15,                 //只是起计算页数的作用，不影响表面,内部影响start 和 limit
           store: EHSubmit.BBS.Ann.store,
           displayInfo: true,
           displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
           emptyMsg: "没有记录",
           items: [
            {
                text: '提出问题',
                tooltip: '提出问题',
                iconCls: 'icon-write',
                handler: EHSubmit.BBS.Ann.addAnn
            }
            ]
       },
       listeners: {
           render: function(thisGrid) {
               //----------请求单页数据-----------------
               thisGrid.store.load({ params: { start: 0, limit: 15} });
           },
           cellclick: function(thisGrid, rowIndex, columnIndex, e) {
               var store = thisGrid.getStore();
               var record = store.getAt(rowIndex);
               AnnID = record.data.AID;
               Topic = record.data.Topic;
               Body = record.data.Body;
               DepartmentName = record.data.DepartmentName;
               UserName = record.data.UserName;
               SubmitTime = record.data.SubmitTime;
               mainPanel.showTab(EHSubmit.BBS.View.Tab);
               var viewgrid = Ext.getCmp('ViewGrid');
               //Ext.getCmp('ViewGrid').store.setBaseParam('AnnID', AnnID);
               viewgrid.getStore().reload({ params: { start: 0, limit: 15, AnnID: AnnID} });
               //Ext.getCmp('ViewGrid').getView().refresh();
               document.getElementById("Add_View_AnnInfo").innerHTML = "<table style='font-size:8pt;text-indent:2em'><tr><br>&nbsp;&nbsp;主题：" + Topic + "<br><br>&nbsp;&nbsp;内容：" + Body
                                                                    + "<br><br>&nbsp;&nbsp;专业：" + DepartmentName + "<br></tr></table>";


           },
           rowbodydblclick: function(thisGrid, rowIndex, e) {

               var store = thisGrid.getStore();
               var record = store.getAt(rowIndex);
               AnnID = record.data.AID;
               Topic = record.data.Topic;
               Body = record.data.Body;
               DepartmentName = record.data.DepartmentName;
               UserName = record.data.UserName;
               SubmitTime = record.data.SubmitTime;
               mainPanel.showTab(EHSubmit.BBS.View.Tab);
               //Ext.getCmp('ViewGrid').store.setBaseParam('AnnID', AnnID);
               Ext.getCmp('ViewGrid').store.reload({ params: { start: 0, limit: 15, AnnID: AnnID} });
               //Ext.getCmp('ViewGrid').getView().refresh();
               document.getElementById("Add_View_AnnInfo").innerHTML = "<table style='font-size:8pt;text-indent:2em'><tr><br>&nbsp;&nbsp;主题：" + Topic + "<br><br>&nbsp;&nbsp;内容：" + Body
                                                                    + "<br><br>&nbsp;&nbsp;专业：" + DepartmentName + "<br></tr></table>";

           },
           rowbodyclick: function(thisGrid, rowIndex, e) {

               var store = thisGrid.getStore();
               var record = store.getAt(rowIndex);
               AnnID = record.data.AID;
               Topic = record.data.Topic;
               Body = record.data.Body;
               DepartmentName = record.data.DepartmentName;
               UserName = record.data.UserName;
               SubmitTime = record.data.SubmitTime;
               mainPanel.showTab(EHSubmit.BBS.View.Tab);
               //Ext.getCmp('ViewGrid').store.setBaseParam('AnnID', AnnID);
               Ext.getCmp('ViewGrid').store.reload({ params: { start: 0, limit: 15, AnnID: AnnID} });
               //Ext.getCmp('ViewGrid').getView().refresh();
               document.getElementById("Add_View_AnnInfo").innerHTML = "<table style='font-size:8pt;text-indent:2em'><tr><br>&nbsp;&nbsp;主题：" + Topic + "<br><br>&nbsp;&nbsp;内容：" + Body
                                                                    + "<br><br>&nbsp;&nbsp;专业：" + DepartmentName + "<br></tr></table>";
           }
       }
   };

   function toggleDetails(btn, pressed) {
       var view = Ext.getCmp('AnnGrid').getView();
       view.showPreview = pressed;
       view.refresh();
   }





//------浏览帖子的主界面-----------------
EHSubmit.BBS.Ann.form = {
    xtype: 'form',         
    id: 'BBSForm',
    title: '答疑平台',
    frame: false,
    bodyStyle: 'padding:15px;',
    border: false,
    closable: true,
    items: [EHSubmit.BBS.Ann.grid]
};
